@section('content')
<div class="am-cf am-padding">
   <div class="am-fl am-cf">
      <strong class="am-text-primary am-text-lg">产品类别</strong>
   </div>
</div>
    <div class="am-g">
      <div class="am-u-md-6 am-cf">
        <div class="am-fl am-cf">
          <div class="am-btn-toolbar am-fl">
            <div class="am-btn-group am-btn-group-xs">
              <a class="am-btn am-btn-primary" href="{{URL::route('notice.add.show')}}"><span class="am-icon-plus"></span> 新增</a>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="am-g">
      <div class="am-u-sm-12">
          <table class="am-table am-table-striped am-table-hover table-main">
            <thead>
              <tr>
                <th>ID</th>
                <th>标题</th>
                <th>内容</th>
                <th>起始时间</th>
                <th>结束时间</th>
                <th>操作</th>
              </tr>
          </thead>
          <tbody>
          	@foreach ($notices as $n)
            <tr data-id="{{$n->id}}" data-title="{{$n->title}}">
              <td>{{$n->id}}</td>
              <td>{{$n->title}}</td>
              <td>{{$n->content}}</td>
              <td>{{$n->start}}</td>
              <td>{{$n->end}}</td>
              <td>操作</td>
              <td>
                <div class="am-btn-toolbar">
                  <div class="am-btn-group am-btn-group-xs">
                    <a class="am-btn am-btn-default am-btn-xs am-text-secondary" href="{{URL::route('notice.update.show',$n->id)}}"><span class="am-icon-pencil-square-o"></span> 编辑</a>
                  	<button class="am-btn am-btn-default am-btn-xs am-text-danger delete-notice"
                    	data-am-loading="{loadingText: '删除中...'}"><span class="am-icon-trash-o"></span> 删除</button>
                  </div>
                </div>
              </td>
            </tr>
            @endforeach
          </tbody>
        </table>
        <div class="am-cf">
		  <div class="am-fr">
		  	<!-- 分页列表 -->
		  	{{$notices->links("admin.slider")}}
		  </div>
		</div>
      </div>
    </div>
<div class="am-modal am-modal-confirm" tabindex="-1" id="delete-confirm">
  <div class="am-modal-dialog">
    <div class="am-modal-hd"></div>
    <div class="am-modal-bd">确认删除吗？</div>
    <div class="am-modal-footer">
      <span class="am-modal-btn" data-am-modal-cancel>取消</span>
      <span class="am-modal-btn" data-am-modal-confirm>确定</span>
    </div>
  </div>
</div>

<div class="am-modal am-modal-alert" tabindex="-1" id="msg-alert">
  <div class="am-modal-dialog">
    <div class="am-modal-hd"></div>
    <div class="am-modal-bd">
    </div>
    <div class="am-modal-footer">
      <span class="am-modal-btn">确定</span>
    </div>
  </div>
</div>
@stop


@section('script')
<style>
/**
 * 复写am-dimmer的透明动画，避免模态框的问题
 */
.am-dimmer{
	-webkit-transition: none;
	transition:none;
}
</style>
<script type="text/javascript">
$(function () {
	$(".delete-notice").on("click",function(){
		$btn = $(this);
		$tr = $(this).closest("tr");
		$('#delete-confirm').find(".am-modal-hd").text($tr.data().title);
		$('#delete-confirm').modal({
	        relatedTarget: this,
	        onConfirm: function(options) {
	          $('#delete-confirm').modal("close");
	          $btn.button("loading");
	          $.post("{{URL::route('notice.delete')}}",$tr.data(),function(data){
	        	  $btn.button('reset');
		  		  if (data.success){
		  				$tr.remove();
		  		  } else {
			  			$('#msg-alert').find(".am-modal-bd").text(data.error);
			  			$('#msg-alert').modal();
				  }
		  	  });
	        },
	        onCancel: function() {
	        }
	    });
	});
	$('#delete-confirm,#msg-alert').on('closed.modal.amui', function() {
		  $(".am-dimmer").hide();
	});
});
</script>
@stop
